#pragma once

#include <cstdint>
#include <optional>
#include <string>
#include <sys/types.h>

typedef struct {
	uint8_t state; // 0 = off, 1 = single shoot, 2 = continuous shoot
	uint8_t bullets_count; // number of bullets to shoot
	uint32_t frequency; // number of bullets to shoot in a second
} __attribute__((packed)) shoot_status_t;

typedef struct {
    int32_t gimbal_yaw;
    int32_t gimbal_pitch;
    shoot_status_t shoot_status;
    uint8_t auto_status;
} __attribute__((packed)) incoming_msg; //feedback

typedef struct {
    int32_t gimbal_yaw;
    int32_t gimbal_pitch;
    shoot_status_t shoot_status;
} __attribute__((packed)) outgoing_msg; //control

class DemoBoard {
  public:
	DemoBoard(const std::string &path);
    ~DemoBoard();
	std::optional<incoming_msg> poll_message();
	void send_message(const outgoing_msg &msg_out);

  private:
    static constexpr size_t READ_BUF_SIZE = 4096;
	int fd;
	incoming_msg msg;
	ssize_t msg_len;
    uint8_t read_buf[READ_BUF_SIZE];
    bool received_byte(uint8_t b);
};
